<?php

namespace common\models\farmerhouse;

use common\models\business\BusinessUser;
use Yii;

/**
 * This is the model class for table "farmerhouse_travels".
 *
 * @property string $id
 * @property integer $userid
 * @property integer $houseid
 * @property string $title
 * @property integer $station
 * @property string $address
 * @property integer $day
 * @property string $picture
 * @property string $content
 * @property integer $status
 * @property integer $createtime
 */
class FarmerhouseTravels extends \yii\db\ActiveRecord
{


    //状状态，0，未审核，1，审核通过，-1，审核不通过
    const STATUS_AGREE = 1;
    const STATUS_DISAGREE = -1;

    public static $statues = [
        self::STATUS_AGREE => '通过',
        self::STATUS_DISAGREE => '不通过',
    ];


    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '农家乐游记',      //用于修改了什么的显示
        'mainfield' => 'title',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>['createtime'],      //不需要记录的字段
    ];



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'farmerhouse_travels';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['userid', 'houseid', 'title', 'status', 'createtime'], 'required'],
            [['userid', 'houseid', 'status', 'createtime'], 'integer'],
            [['title'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'userid' => '书写人',
            'houseid' => '农家乐',
            'title' => '标题',
            'status' => '状态',
            'createtime' => '创建时间',
        ];
    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取评论人
     */
    public function getUser()
    {
        return $this->hasOne(BusinessUser::className(),['id'=>'userid']);
    }


    public function getHouse()
    {
        return $this->hasOne(FarmerhouseHouse::className(),['id'=>'houseid']);
    }


    public function getDetail()
    {
        return $this->hasMany(FarmerhouseTravelsDetail::className(),['travelid'=>'id']);
    }


}
